<template>
  <div class="window">
    <!--搜索框-->
    <div class="windows">
      <img src="../../../assets/common/back.png" alt="" id="imgs" @click="doClick">
      <input type="text" placeholder="🔍输入商品关键字" v-model="docus">
      <div class="ontxt" @click="doDinj">搜索</div>
    </div>
    <!--子路由出现位置-->
    <router-view :oust="positin"></router-view>
    <!--搜索结果-->
    <div v-if="isCuse">
      <div class="ponetin">亲们都在找</div>
      <div class="incuk">
        <ul>
          <li>面膜</li>
          <li>防晒</li>
          <li>眼霜</li>
          <li>精华</li>
        </ul>
        <ul>
          <li>洗面奶</li>
          <li>资生堂</li>
          <li>洗发水</li>
          <li>防晒喷雾</li>
        </ul>
        <ul>
          <li>洗面奶</li>
          <li>资生堂</li>
          <li>洗发水</li>
          <li>防晒喷雾</li>
        </ul>
      </div>
      <!--浏览历史-->
      <div class="isshow" v-show="isBunt">
        <div class="ponetin1">
          <p>最近搜索</p>
        </div>
        <ul class="uls" v-for="item in arStu">
          <li>{{item.name}}</li>
        </ul>
        <div class="delete">
          <p @click="doDelete">
            清空搜索历史
          </p>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  import Vue from 'vue'
  export default {
    data() {
      return {
        isBunt: false,
        arStu: [],
        docus: '',
        isCuse: true,
        positin: []
      }
    },
    mounted() {
      this.doGet();
    },
    methods: {
      doClick() {
        this.$router.go(-1);
        this.isCuse = true;
        this.doGet();
        this.isBunt = false;
      },
      doDinj() {
        if (this.docus != '') {
          for (var i = 0; i < this.arStu.length; i++) {
            if (this.docus != this.arStu[i]) {
              this.arStu.push(this.docus);
            }
          }
          Vue.axios.get('/goods/accept', {
            params: {
              ID: 10086,
              name: this.docus
            }
          }).then((res) => {
          });
          Vue.axios.get('/goods/seek', {
            params: {
              name: this.docus
            }
          }).then((re) => {
            console.log('模糊搜索到的:', re.data);
            this.positin = re.data;
          });
          this.$router.push({name: 'home/sousuo/success'});
          this.isCuse = false;
        }
      },
      doDelete() {
        this.arStu.splice(0, this.arStu.length);
        Vue.axios.get('/goods/delete').then((resunt) => {
        });
      },
      doGet() {
        Vue.axios.get('/goods/jsoness').then((resul) => {
          this.arStu = resul.data
        })
      }
    },
    beforeUpdate () {
      if (this.arStu.length > 0) {
        this.isBunt = true;
      }
    },
  }
</script>
<style scoped>
  .windows {
    background: #e53e42;
    width: 100%;
    padding-top: 2.5rem;
    padding-bottom: 1.5rem;
    display: flex;
    justify-content: space-around;
  }
  #imgs {
    display: inline-block;
    height: 1.8rem;
    margin-top: 0.2rem;
  }
  input {
    width: 22rem;
    height: 2rem;
    padding-left: 0.5rem;
    border-radius: 5px;
    border: 1px solid white;
    font-size: 1.3rem;
  }
  input:-moz-placeholder,
  textarea:-moz-placeholder {
    color: #e83d41;
  }

  input:-ms-input-placeholder,
  textarea:-ms-input-placeholder {
    color: #e83d41;
  }

  input::-webkit-input-placeholder,
  textarea::-webkit-input-placeholder {
    color: #e83d41;
  }
  .ontxt {
    font-size: 1.6rem;
    line-height: 2rem;
    color: white;
    font-weight: 200;
  }
  .ponetin1,
  .ponetin {
    font-size: 1.4rem;
    font-weight: 300;
    background: rgb(242, 242, 242);
    height: 3rem;
    line-height: 3rem;
    padding-left: 1rem;
    color: #808080;
  }
  .incuk {
    height: 16.5rem;
  }
  .incuk li {
    display: inline-block;
    border: 1px solid #cccccc;
    border-radius: 10px;
    padding: 0 0.8rem 0 0.8rem;
    font-size: 1.4rem;
    margin: 0.5rem;
    color: #4d4d4d;
    font-weight: 300;
  }
  .uls li {
    font-size: 1.5rem;
    margin: 0.5rem 0 0.3rem 1rem;
    font-weight: 200;
  }
  .delete {
    border-top: 1px solid #cccccc;
    text-align: center;
    padding-top: 1.5rem;
  }
  .delete p {
    width: 20rem;
    border: 1px solid #cccccc;
    margin: auto;
    font-size: 1.3rem;
    color: #808080;
    border-radius: 10px;
  }
</style>
